import {createStore, combineReducers} from "redux";
// import produce from 'immer';

// 定义修改规则
export const countReducer = (state = 0, {type, payload = 1}) => {
  switch (type) {
    case "ADD":
      return state + payload;
    case "MINUS":
      return state - payload;
    default:
      return state;
  }
};


const initialState = {
  currentPage : 'chapter',
  currentHl : 0
};

export const diaguleReducer = (state = initialState, {type, payload='page'}) => {
  switch (type) {
    case 'CHANAGE_PAGE':
      return {
        ...state,
        currentPage : payload
      }
    case 'UPDATE_DL':
      return {
        ...state,
        currentHl : payload
      }
    default:
      return state
  }
}

// 创建一个数据仓库
const store = createStore(combineReducers({  diagule: diaguleReducer, count: countReducer, }));

export default store;
